package com.mes.cloud.web;

import com.mes.cloud.api.dto.request.BaseEmployeeMyMenuRequest;
import com.mes.cloud.api.dto.request.employee.*;
import com.mes.cloud.api.dto.response.BaseEmployeeDto;
import com.mes.cloud.api.dto.response.employee.BaseEmployeeOrganizationDto;
import com.mes.cloud.api.dto.response.employee.BaseEmployeePositionCustomerDto;
import com.mes.cloud.api.dto.response.menu.MyMenuDto;
import com.mes.cloud.common.CommPager;
import com.mes.cloud.common.JsonResult;
import com.mes.cloud.enums.HttpStatusEnum;
import com.mes.cloud.service.BaseEmployeeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Set;

/**
 * @author Mr.zhang
 * @version 2019-07-31 10:42:39
 * @email 407892370@qq.com
 */
@Api(tags = "系统员工表", value = "系统员工表接口")
@RestController
@RequestMapping(value = "/baseEmployee")
public class BaseEmployeeController  {

    private BaseEmployeeService baseEmployeeService;

    @Autowired
    public BaseEmployeeController(BaseEmployeeService baseEmployeeService) {
        this.baseEmployeeService = baseEmployeeService;
    }

    @ApiOperation(value = "系统员工表分页查询", notes = "系统员工表分页查询")
    @PostMapping(value = "/listPage")
    public JsonResult<CommPager<BaseEmployeeDto>> listPage(@RequestBody BaseEmployeePageRequest pageRequest) {
        CommPager<BaseEmployeeDto> commPager = baseEmployeeService.selectPage(pageRequest);
        JsonResult<CommPager<BaseEmployeeDto>> jsonResult = new JsonResult<>();
        jsonResult.setMsg(HttpStatusEnum.OK.getMessage());
        jsonResult.setCode(HttpStatusEnum.OK.getCode());
        jsonResult.setData(commPager);
        return jsonResult;
    }

    @ApiOperation(value = "系统员工表查询所有", notes = "系统员工表查询所有")
    @PostMapping(value = "/list")
    public JsonResult<List<BaseEmployeeDto>> list(@RequestBody BaseEmployeeRequest baseEmployeeRequest) {
        List<BaseEmployeeDto> list = baseEmployeeService.list(baseEmployeeRequest);
        JsonResult<List<BaseEmployeeDto>> jsonResult = new JsonResult<>();
        jsonResult.setMsg(HttpStatusEnum.OK.getMessage());
        jsonResult.setCode(HttpStatusEnum.OK.getCode());
        jsonResult.setData(list);
        return jsonResult;
    }

    @ApiOperation(value = "系统员工表新增", notes = "系统员工表新增")
    @PostMapping(value = "/add")
    public JsonResult add(@Valid @RequestBody BaseEmployeeRequest baseEmployeeRequest) {
        return baseEmployeeService.insertSelective(baseEmployeeRequest);
    }

    @ApiOperation(value = "系统员工表修改", notes = "系统员工表修改")
    @PostMapping(value = "/update")
    public JsonResult update(@Valid @RequestBody BaseEmployeeRequest baseEmployeeRequest) {
        return baseEmployeeService.updateSelectiveById(baseEmployeeRequest);

    }


    @ApiOperation(value = "系统员工表查看详情", notes = "系统员工表查看详情")
    @ApiImplicitParam(paramType = "String", name = "id", value = "系统员工表主键", required = true)
    @GetMapping(value = "get/{id}")
    public JsonResult<BaseEmployeeDto> get(@NotEmpty(message = "id不能为空！") @PathVariable String id) {
        return baseEmployeeService.get(id);
    }

    @ApiOperation(value = "获取我的菜单", notes = "获取我的菜单")
    @PostMapping(value = "/myMenuList")
    public JsonResult<List<MyMenuDto>> myMenuList(@RequestBody BaseEmployeeMyMenuRequest baseEmployeeMyMenuRequest) {
        return baseEmployeeService.myMenuList(baseEmployeeMyMenuRequest);
    }


    @ApiOperation(value = "通过工号获取权限", notes = "通过工号获取权限")
    @PostMapping(value = "/getAuthUrlByEmployeeNo")
    public JsonResult<Set<String>> getAuthUrlByEmployeeNo() {
        return baseEmployeeService.getAuthUrlByEmployeeNo();
    }

    @ApiOperation(value = "通过工号获取员工信息", notes = "通过工号获取权限")
    @PostMapping(value = "/getByEmployeeNo")
    public JsonResult<BaseEmployeeDto> getByEmployeeNo() {
        return baseEmployeeService.getByEmployeeNo();
    }

    @ApiOperation(value = "通过工号获取员工信息", notes = "通过工号获取权限")
    @GetMapping(value = "/isExist/{employeeNo}")
    public JsonResult isExist(@NotEmpty(message = "employeeNo不能为空！") @PathVariable String employeeNo) {
        return baseEmployeeService.isExist(employeeNo);
    }

    @ApiOperation(value = "更新员工授权方式", notes = "更新员工授权方式")
    @GetMapping(value = "updateAuthorisationType/{id}/{authorisationType}")
    public JsonResult updateAuthorisationType(@PathVariable String id,@PathVariable int authorisationType) {
        return baseEmployeeService.updateAuthorisationType(id,authorisationType);
    }

    @ApiOperation(value = "员工批量离职", notes = "员工批量离职")
    @PostMapping(value = "/batchStatus")
    public JsonResult batchStatus(@RequestBody BaseEmployeeStatusRequest baseEmployeeStatusRequest) {
        return baseEmployeeService.batchStatus(baseEmployeeStatusRequest);
    }

    @ApiOperation(value = "组织员工查询", notes = "组织员工查询")
    @PostMapping(value = "/listPageByOrgId")
    public JsonResult<CommPager<BaseEmployeeOrganizationDto>> listPageByOrgId(@RequestBody BaseEmployeeOrganizationPageRequest pageRequest) {
        CommPager<BaseEmployeeOrganizationDto> commPager = baseEmployeeService.listPageByOrgId(pageRequest);
        JsonResult<CommPager<BaseEmployeeOrganizationDto>> jsonResult = new JsonResult<>();
        jsonResult.setMsg(HttpStatusEnum.OK.getMessage());
        jsonResult.setCode(HttpStatusEnum.OK.getCode());
        jsonResult.setData(commPager);
        return jsonResult;
    }

    @ApiOperation(value = "查询岗位下员工", notes = "查询岗位下员工")
    @PostMapping(value = "/listPageByPositionId")
    public JsonResult<CommPager<BaseEmployeePositionCustomerDto>> listPageByPositionId(@Valid @RequestBody BaseEmployeePositionPageRequest pageRequest) {
        CommPager<BaseEmployeePositionCustomerDto> commPager = baseEmployeeService.listPageByPositionId(pageRequest);
        JsonResult<CommPager<BaseEmployeePositionCustomerDto>> jsonResult = new JsonResult<>();
        jsonResult.setMsg(HttpStatusEnum.OK.getMessage());
        jsonResult.setCode(HttpStatusEnum.OK.getCode());
        jsonResult.setData(commPager);
        return jsonResult;
    }


    @ApiOperation(value = "同步员工查询", notes = "同步员工查询")
    @PostMapping(value = "/synchroDataList")
    public JsonResult<List<BaseEmployeeOrganizationDto>> synchroDataList(@Valid @RequestBody List<String> employeeNos) {
        return baseEmployeeService.synchroDataList(employeeNos);
    }

    /**
     * 通过员工岗位关联的岗位类型，岗位类型关联的角色，更新员工的角色（只做新增）
     * @param baseEmployeeUpdateRoleByPositionTypeRequest
     * @return
     */
    @ApiOperation(value = "员工更新角色", notes = "员工更新角色")
    @PostMapping(value = "/updateRoleByPositionType")
    public JsonResult updateRoleByPositionType(@Valid @RequestBody BaseEmployeeUpdateRoleByPositionTypeRequest baseEmployeeUpdateRoleByPositionTypeRequest) {
        return baseEmployeeService.updateRoleByPositionType(baseEmployeeUpdateRoleByPositionTypeRequest);
    }

    @ApiOperation(value = "获取我的菜单", notes = "获取我的菜单")
    @PostMapping(value = "/myMenuListMenu")
    public JsonResult<List<MyMenuDto>> myMenuListMenu(@Valid @RequestBody BaseEmployeeMyMenuRequest baseEmployeeMyMenuRequest) {
        return baseEmployeeService.myMenuListMenu(baseEmployeeMyMenuRequest);
    }
}
